//
//  CYGDetailSelectView.m
//  CYGHuntForCity
//
//  Created by cygarm on 16/3/22.
//  Copyright © 2016年 cygarm. All rights reserved.
//

#import "CYGDetailSelectView.h"
#import "CYGButtonNoHighlight.h"

@interface CYGDetailSelectView ()

@property (weak, nonatomic) IBOutlet CYGButtonNoHighlight *rcmdBtn;
@property (weak, nonatomic) IBOutlet CYGButtonNoHighlight *infoBtn;
@property (strong, nonatomic) UIView *selectLine;

@end

@implementation CYGDetailSelectView

- (void)awakeFromNib {

}

- (instancetype)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
		[self setupUI];
	}
	
	return self;
}

- (void)setupUI {
	self.rcmdBtn.tag = CYGDetailSelectViewTagRcmdBtn;
	self.infoBtn.tag = CYGDetailSelectViewTagInfoBtn;
	
	self.selectLine = [[UIView alloc] init];
	self.selectLine.backgroundColor = CYGGolbalGreen;
	self.selectLine.layer.masksToBounds = YES;
	self.selectLine.layer.cornerRadius = 2;
	[self addSubview:self.selectLine];
}

- (void)layoutSubviews {
	self.selectLine.frame = CGRectMake(CYGViewRealX(self.rcmdBtn), self.bounds.size.height-4, self.rcmdBtn.bounds.size.width, 4);
}

- (IBAction)btnClick:(id)sender {
	UIButton *btn = (UIButton*)sender;
	
	if (self.selectLine.frame.origin.x != btn.frame.origin.x) {
		CGRect frame = self.selectLine.frame;
		frame.origin.x = CYGViewRealX(btn);
		[UIView animateWithDuration:0.3f animations:^{
			self.selectLine.frame = frame;
		}];
	}
	
	[self.delegate detailSelectViewBtnClick:btn.tag];
}

- (void)selectBtn:(CYGDetailSelectViewTag)tag {
	[self btnClick:[self viewWithTag:tag]];
}


@end
